import axios from 'axios';
import {message} from 'antd';
import {REACT_APP_AUTH} from "../../config";
import * as LZString from "lz-string";
import { tokenIns } from "@mdt/utils/dist/tokenUtil";
// const currToken = async ()=>{
//     const ken="BwQwrAxgjBCmDsBaAJgMwAxkQFlgTgkQCMIiAmRKECUgNlnVmDFSA";
//     return await REACT_APP_AUTH === "cust_dev" ? LZString.decompressFromEncodedURIComponent(ken) : tokenIns.get();
// };
// currToken().then(res=>{
//     localStorage.setItem('t', res);
// });
import { BASE_URL_COLLECTOR, REACT_APP_AUTH } from "../../config";
const file_path = REACT_APP_AUTH === "cust_dev" ? "/apiColl" : BASE_URL_COLLECTOR;
const instance = axios.create({
    baseURL: file_path,
    timeout: 40000
});
instance.interceptors.request.use((config) => {
    message.loading('加载中...', 0);
    config.headers.Authorization =localStorage.getItem('t');
    return config;
}, (error) => {
    return Promise.reject(error);
});
instance.interceptors.response.use((response) => {
    message.destroy();
    return Promise.resolve(response.data);
}, (error) => {
    message.destroy();
    if(String(error).indexOf('timeout')>=0) return Promise.reject({msg:"请求超时！"});
    if(String(error).indexOf('401')>=0) return Promise.reject({msg:401})
    return Promise.reject({msg:"请求错误！"});
});
export default instance;
